#include "EditorPageAreaManagerView.h"
#include "EditorPageAreaManagerViewModel.h"
#include "Object/NewObject.h"
#include "Widgets/Splitable/EditorSplitableLayoutView.h"
#include "Widgets/Widget.h"

void REditorPageAreaManagerView::BindViewModel(TSharedObjectPtr<REditorPageAreaManagerViewModel> InViewModel)
{
    ViewModel = InViewModel;
    
    LayoutModel = NewObject<REditorSplitableLayoutView>(this);
    LayoutModel->OnBindItemView.BindLambda(
        [this](TSharedObjectPtr<RObject> ItemViewModel)
        {
            TSharedObjectPtr<REditorPageAreaViewModel> PageAreaViewModel = ItemViewModel;
            auto PageAreaView = NewObject<REditorPageAreaView>(this);
            PageAreaView->BindViewModel(PageAreaViewModel);
            return PageAreaView;
        }
    );  
    LayoutModel->OnFillItemWidget.BindLambda(
        [this](
            TSharedObjectPtr<RObject> ItemView,
            TSharedObjectPtr<RWidget> ParentWidget)
        {
            TSharedObjectPtr<REditorPageAreaView>
                PageAreaView = ItemView;
            PageAreaView->CreateWidget(ParentWidget);
        }
    );

    LayoutModel->BindViewModel(ViewModel->GetLayout());
}

void REditorPageAreaManagerView::CreateWidget(TSharedObjectPtr<RWidget> InParent)
{
    LayoutModel->CreateWidget(InParent);
}
